package com.pzh.assignment.common.bean.vo;

import com.pzh.assignment.common.bean.GlobalConstant;
import com.pzh.assignment.entity.Semester;
import lombok.Data;

import java.time.format.DateTimeFormatter;


@Data
public class SemesterVO {
    private Integer id;

    private Integer year;

    private Integer number;

    private String createTime;

    private String updateTime;

    public static SemesterVO valueOf(Semester semester) {
        SemesterVO vo = new SemesterVO();
        vo.setId(semester.getId());
        vo.setYear(semester.getYear());
        vo.setNumber(semester.getNumber());
        if (semester.getCreateTime() != null) {
            vo.setCreateTime(semester.getCreateTime().format(DateTimeFormatter.ofPattern(GlobalConstant.DATE_FORMAT_PATTERN)));
        }
        if (semester.getUpdateTime() != null) {
            vo.setUpdateTime(semester.getUpdateTime().format(DateTimeFormatter.ofPattern(GlobalConstant.DATE_FORMAT_PATTERN)));
        }
        return vo;
    }
}
